.class public Lcom/teewoo/app/bus/manager/history/ChangeHistoryManager;
.super Ljava/lang/Object;
.source "ChangeHistoryManager.java"


# instance fields
.field private dbInstance:Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;


# direct methods
.method public constructor <init>(Landroid/content/Context;)V
    .locals 1
    .parameter "context"

    .prologue
    .line 20
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 21
    new-instance v0, Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;

    invoke-direct {v0, p1}, Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;-><init>(Landroid/content/Context;)V

    iput-object v0, p0, Lcom/teewoo/app/bus/manager/history/ChangeHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;

    .line 22
    return-void
.end method


# virtual methods
.method public delete(Ljava/lang/Integer;)V
    .locals 4
    .parameter "id"

    .prologue
    .line 42
    iget-object v1, p0, Lcom/teewoo/app/bus/manager/history/ChangeHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;

    invoke-virtual {v1}, Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v0

    .line 43
    .local v0, database:Landroid/database/sqlite/SQLiteDatabase;
    const-string v1, "delete from change_history where _id = ?"

    const/4 v2, 0x1

    new-array v2, v2, [Ljava/lang/Object;

    const/4 v3, 0x0

    aput-object p1, v2, v3

    invoke-virtual {v0, v1, v2}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;[Ljava/lang/Object;)V

    .line 44
    invoke-virtual {v0}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 45
    return-void
.end method

.method public deleteAll()V
    .locals 3

    .prologue
    .line 52
    iget-object v1, p0, Lcom/teewoo/app/bus/manager/history/ChangeHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;

    invoke-virtual {v1}, Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v0

    .line 53
    .local v0, database:Landroid/database/sqlite/SQLiteDatabase;
    const-string v1, "delete from change_history"

    const/4 v2, 0x0

    new-array v2, v2, [Ljava/lang/Object;

    invoke-virtual {v0, v1, v2}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;[Ljava/lang/Object;)V

    .line 54
    invoke-virtual {v0}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 55
    return-void
.end method

.method public find(II)Lcom/teewoo/app/bus/model/history/ChangeHistory;
    .locals 9
    .parameter "fromId"
    .parameter "toId"

    .prologue
    const/4 v8, 0x2

    const/4 v5, 0x1

    const/4 v4, 0x0

    .line 65
    iget-object v1, p0, Lcom/teewoo/app/bus/manager/history/ChangeHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;

    invoke-virtual {v1}, Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v7

    .line 66
    .local v7, database:Landroid/database/sqlite/SQLiteDatabase;
    const/4 v0, 0x0

    .line 69
    .local v0, tempHis:Lcom/teewoo/app/bus/model/history/ChangeHistory;
    const-string v1, "select * from change_history where from_id = ? and to_id = ?"

    .line 70
    new-array v2, v8, [Ljava/lang/String;

    invoke-static {p1}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;

    move-result-object v3

    aput-object v3, v2, v4

    .line 71
    invoke-static {p2}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;

    move-result-object v3

    aput-object v3, v2, v5

    .line 68
    invoke-virtual {v7, v1, v2}, Landroid/database/sqlite/SQLiteDatabase;->rawQuery(Ljava/lang/String;[Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v6

    .line 73
    .local v6, cursor:Landroid/database/Cursor;
    invoke-interface {v6}, Landroid/database/Cursor;->moveToFirst()Z

    move-result v1

    if-eqz v1, :cond_0

    .line 74
    new-instance v0, Lcom/teewoo/app/bus/model/history/ChangeHistory;

    .end local v0           #tempHis:Lcom/teewoo/app/bus/model/history/ChangeHistory;
    invoke-interface {v6, v4}, Landroid/database/Cursor;->getInt(I)I

    move-result v1

    invoke-static {v1}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v1

    invoke-interface {v6, v5}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object v2

    .line 75
    invoke-interface {v6, v8}, Landroid/database/Cursor;->getInt(I)I

    move-result v3

    invoke-static {v3}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v3

    const/4 v4, 0x3

    invoke-interface {v6, v4}, Landroid/database/Cursor;->getInt(I)I

    move-result v4

    invoke-static {v4}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v4

    const/4 v5, 0x4

    invoke-interface {v6, v5}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object v5

    .line 74
    invoke-direct/range {v0 .. v5}, Lcom/teewoo/app/bus/model/history/ChangeHistory;-><init>(Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/String;)V

    .line 77
    .restart local v0       #tempHis:Lcom/teewoo/app/bus/model/history/ChangeHistory;
    :cond_0
    invoke-interface {v6}, Landroid/database/Cursor;->close()V

    .line 78
    invoke-virtual {v7}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 79
    return-object v0
.end method

.method public findByIds(II)Lcom/teewoo/app/bus/model/history/ChangeHistory;
    .locals 9
    .parameter "fromId"
    .parameter "toId"

    .prologue
    const/4 v8, 0x2

    const/4 v5, 0x1

    const/4 v4, 0x0

    .line 88
    iget-object v1, p0, Lcom/teewoo/app/bus/manager/history/ChangeHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;

    invoke-virtual {v1}, Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;->getReadableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v7

    .line 89
    .local v7, database:Landroid/database/sqlite/SQLiteDatabase;
    const/4 v0, 0x0

    .line 91
    .local v0, tempHis:Lcom/teewoo/app/bus/model/history/ChangeHistory;
    const-string v1, "select * from change_history where from_id = ? and to_id = ?"

    .line 92
    new-array v2, v8, [Ljava/lang/String;

    invoke-static {p1}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;

    move-result-object v3

    aput-object v3, v2, v4

    invoke-static {p2}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;

    move-result-object v3

    aput-object v3, v2, v5

    .line 91
    invoke-virtual {v7, v1, v2}, Landroid/database/sqlite/SQLiteDatabase;->rawQuery(Ljava/lang/String;[Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v6

    .line 94
    .local v6, cursor:Landroid/database/Cursor;
    invoke-interface {v6}, Landroid/database/Cursor;->moveToFirst()Z

    move-result v1

    if-eqz v1, :cond_0

    .line 95
    new-instance v0, Lcom/teewoo/app/bus/model/history/ChangeHistory;

    .end local v0           #tempHis:Lcom/teewoo/app/bus/model/history/ChangeHistory;
    invoke-interface {v6, v4}, Landroid/database/Cursor;->getInt(I)I

    move-result v1

    invoke-static {v1}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v1

    invoke-interface {v6, v5}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object v2

    .line 96
    invoke-interface {v6, v8}, Landroid/database/Cursor;->getInt(I)I

    move-result v3

    invoke-static {v3}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v3

    const/4 v4, 0x3

    invoke-interface {v6, v4}, Landroid/database/Cursor;->getInt(I)I

    move-result v4

    invoke-static {v4}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v4

    const/4 v5, 0x4

    invoke-interface {v6, v5}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object v5

    .line 95
    invoke-direct/range {v0 .. v5}, Lcom/teewoo/app/bus/model/history/ChangeHistory;-><init>(Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/String;)V

    .line 98
    .restart local v0       #tempHis:Lcom/teewoo/app/bus/model/history/ChangeHistory;
    :cond_0
    if-eqz v6, :cond_1

    .line 99
    invoke-interface {v6}, Landroid/database/Cursor;->close()V

    .line 100
    invoke-virtual {v7}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 102
    :cond_1
    return-object v0
.end method

.method public getAll()Ljava/util/List;
    .locals 10
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "()",
            "Ljava/util/List",
            "<",
            "Lcom/teewoo/app/bus/model/history/ChangeHistory;",
            ">;"
        }
    .end annotation

    .prologue
    const/4 v9, 0x0

    .line 126
    new-instance v8, Ljava/util/ArrayList;

    invoke-direct {v8}, Ljava/util/ArrayList;-><init>()V

    .line 127
    .local v8, list:Ljava/util/List;,"Ljava/util/List<Lcom/teewoo/app/bus/model/history/ChangeHistory;>;"
    iget-object v0, p0, Lcom/teewoo/app/bus/manager/history/ChangeHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;

    invoke-virtual {v0}, Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;->getReadableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v7

    .line 129
    .local v7, database:Landroid/database/sqlite/SQLiteDatabase;
    const-string v0, "select * from change_history ORDER BY search_time DESC"

    .line 130
    new-array v1, v9, [Ljava/lang/String;

    .line 128
    invoke-virtual {v7, v0, v1}, Landroid/database/sqlite/SQLiteDatabase;->rawQuery(Ljava/lang/String;[Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v6

    .line 131
    .local v6, cursor:Landroid/database/Cursor;
    :goto_0
    invoke-interface {v6}, Landroid/database/Cursor;->moveToNext()Z

    move-result v0

    if-nez v0, :cond_0

    .line 136
    invoke-interface {v6}, Landroid/database/Cursor;->close()V

    .line 137
    invoke-virtual {v7}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 138
    return-object v8

    .line 133
    :cond_0
    new-instance v0, Lcom/teewoo/app/bus/model/history/ChangeHistory;

    invoke-interface {v6, v9}, Landroid/database/Cursor;->getInt(I)I

    move-result v1

    invoke-static {v1}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v1

    const/4 v2, 0x1

    invoke-interface {v6, v2}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object v2

    .line 134
    const/4 v3, 0x2

    invoke-interface {v6, v3}, Landroid/database/Cursor;->getInt(I)I

    move-result v3

    invoke-static {v3}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v3

    const/4 v4, 0x3

    invoke-interface {v6, v4}, Landroid/database/Cursor;->getInt(I)I

    move-result v4

    invoke-static {v4}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v4

    const/4 v5, 0x4

    invoke-interface {v6, v5}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object v5

    invoke-direct/range {v0 .. v5}, Lcom/teewoo/app/bus/model/history/ChangeHistory;-><init>(Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/String;)V

    .line 133
    invoke-interface {v8, v0}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    goto :goto_0
.end method

.method public getCount()J
    .locals 4

    .prologue
    .line 167
    iget-object v2, p0, Lcom/teewoo/app/bus/manager/history/ChangeHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;

    invoke-virtual {v2}, Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v1

    .line 169
    .local v1, database:Landroid/database/sqlite/SQLiteDatabase;
    const-string v2, "select count(*) from change_history"

    const/4 v3, 0x0

    .line 168
    invoke-virtual {v1, v2, v3}, Landroid/database/sqlite/SQLiteDatabase;->rawQuery(Ljava/lang/String;[Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v0

    .line 171
    .local v0, cursor:Landroid/database/Cursor;
    invoke-interface {v0}, Landroid/database/Cursor;->moveToNext()Z

    move-result v2

    if-eqz v2, :cond_0

    .line 172
    invoke-virtual {v1}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 173
    const/4 v2, 0x0

    invoke-interface {v0, v2}, Landroid/database/Cursor;->getLong(I)J

    move-result-wide v2

    .line 176
    :goto_0
    return-wide v2

    .line 175
    :cond_0
    invoke-virtual {v1}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 176
    const-wide/16 v2, 0x0

    goto :goto_0
.end method

.method public getRawAll()Landroid/database/Cursor;
    .locals 5

    .prologue
    .line 148
    const/4 v2, 0x0

    .line 149
    .local v2, tempCur:Landroid/database/Cursor;
    iget-object v3, p0, Lcom/teewoo/app/bus/manager/history/ChangeHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;

    invoke-virtual {v3}, Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;->getReadableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v1

    .line 151
    .local v1, database:Landroid/database/sqlite/SQLiteDatabase;
    const-string v3, "select * from change_history ORDER BY search_time DESC"

    .line 152
    const/4 v4, 0x0

    new-array v4, v4, [Ljava/lang/String;

    .line 150
    invoke-virtual {v1, v3, v4}, Landroid/database/sqlite/SQLiteDatabase;->rawQuery(Ljava/lang/String;[Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v0

    .line 153
    .local v0, cursor:Landroid/database/Cursor;
    invoke-interface {v0}, Landroid/database/Cursor;->moveToFirst()Z

    move-result v3

    if-eqz v3, :cond_0

    .line 154
    move-object v2, v0

    .line 156
    :cond_0
    invoke-interface {v0}, Landroid/database/Cursor;->close()V

    .line 157
    invoke-virtual {v1}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 158
    return-object v2
.end method

.method public save(Lcom/teewoo/app/bus/model/history/ChangeHistory;)V
    .locals 5
    .parameter "chHistory"

    .prologue
    .line 30
    iget-object v1, p0, Lcom/teewoo/app/bus/manager/history/ChangeHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;

    invoke-virtual {v1}, Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v0

    .line 31
    .local v0, database:Landroid/database/sqlite/SQLiteDatabase;
    const-string v1, "insert into change_history (keyword,from_id,to_id,search_time) values (?, ?, ?, ?);"

    .line 32
    const/4 v2, 0x4

    new-array v2, v2, [Ljava/lang/Object;

    const/4 v3, 0x0

    invoke-virtual {p1}, Lcom/teewoo/app/bus/model/history/ChangeHistory;->getKeyWord()Ljava/lang/String;

    move-result-object v4

    aput-object v4, v2, v3

    const/4 v3, 0x1

    invoke-virtual {p1}, Lcom/teewoo/app/bus/model/history/ChangeHistory;->getStationFromId()Ljava/lang/Integer;

    move-result-object v4

    aput-object v4, v2, v3

    const/4 v3, 0x2

    invoke-virtual {p1}, Lcom/teewoo/app/bus/model/history/ChangeHistory;->getStationToId()Ljava/lang/Integer;

    move-result-object v4

    aput-object v4, v2, v3

    const/4 v3, 0x3

    invoke-virtual {p1}, Lcom/teewoo/app/bus/model/history/ChangeHistory;->getSearchTime()Ljava/lang/String;

    move-result-object v4

    aput-object v4, v2, v3

    .line 31
    invoke-virtual {v0, v1, v2}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;[Ljava/lang/Object;)V

    .line 33
    invoke-virtual {v0}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 34
    return-void
.end method

.method public update(Lcom/teewoo/app/bus/model/history/ChangeHistory;)V
    .locals 5
    .parameter "chHistory"

    .prologue
    .line 112
    iget-object v1, p0, Lcom/teewoo/app/bus/manager/history/ChangeHistoryManager;->dbInstance:Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;

    invoke-virtual {v1}, Lcom/teewoo/app/bus/db/history/ChangeHistoryDbHelper;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v0

    .line 114
    .local v0, database:Landroid/database/sqlite/SQLiteDatabase;
    const-string v1, "update change_history set keyword=?, from_id=?, to_id=?, search_time=? where _id=?"

    .line 115
    const/4 v2, 0x4

    new-array v2, v2, [Ljava/lang/Object;

    const/4 v3, 0x0

    invoke-virtual {p1}, Lcom/teewoo/app/bus/model/history/ChangeHistory;->getKeyWord()Ljava/lang/String;

    move-result-object v4

    aput-object v4, v2, v3

    const/4 v3, 0x1

    invoke-virtual {p1}, Lcom/teewoo/app/bus/model/history/ChangeHistory;->getStationFromId()Ljava/lang/Integer;

    move-result-object v4

    aput-object v4, v2, v3

    const/4 v3, 0x2

    invoke-virtual {p1}, Lcom/teewoo/app/bus/model/history/ChangeHistory;->getStationToId()Ljava/lang/Integer;

    move-result-object v4

    aput-object v4, v2, v3

    const/4 v3, 0x3

    invoke-virtual {p1}, Lcom/teewoo/app/bus/model/history/ChangeHistory;->getSearchTime()Ljava/lang/String;

    move-result-object v4

    aput-object v4, v2, v3

    .line 113
    invoke-virtual {v0, v1, v2}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;[Ljava/lang/Object;)V

    .line 116
    invoke-virtual {v0}, Landroid/database/sqlite/SQLiteDatabase;->close()V

    .line 117
    return-void
.end method
